﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestStarter.Model
{
    public class ItemStatus
    {
        protected int index;
        protected string name;

        protected static readonly IDictionary<int, ItemStatus> values = new Dictionary<int, ItemStatus>();

        public static readonly ItemStatus PASSED = new ItemStatus(1, "Passed");
        public static readonly ItemStatus FAILED = new ItemStatus(2, "Failed");
        public static readonly ItemStatus SKIPPED = new ItemStatus(3, "Skipped");

        public ItemStatus() { }

        protected ItemStatus(int index, string name)
        {
            this.index = index;
            this.name = name;
            values.Add(index, this);
        }        

        public static implicit operator int(ItemStatus status)
        {
            return status.index;
        }

        public static implicit operator ItemStatus(int index)
        {
            ItemStatus status;
            values.TryGetValue(index, out status);
            return status;
        }

        public override string ToString()
        {
            return this.name;
        }

        public static implicit operator string(ItemStatus status)
        {
            return status == null ? null : status.ToString();
        }

        public static implicit operator ItemStatus(string name)
        {
            return name == null ? null : values.Values.FirstOrDefault(item => name.Equals(item.name, StringComparison.CurrentCultureIgnoreCase));
        }

        public ItemStatus Get(int foo)
        {
            return foo;
        }
    }
}
